<?php

namespace app\report\logic;

use think\facade\Db;
use think\facade\Cache;
use util\Excel;
use think\exception\ValidateException;
use think\facade\Log;
use util\Token;
use util\Upload;
use think\cache\driver\Redis;
use app\order\logic\OrderLogic;
use app\report\logic\MonthlyDistributionLogic;

class MonthlyPersonalLogic
{

    public function __construct()
    {
    }

    /**
     * @param $params
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     * @desc 列表
     * @author zhangheng
     */
    public function index($params = [])
    {
        $AdminId = $params['AdminId'] ?? 0;
        $admin_id = $params['admin_id'] ?? '';
        $date     = $params['date'] ?? '';
        $status     = $params['status'] ?? '';
        $limit = $params['limit'] ?? 10;
        $where = [];

        if ($AdminId == 0) {
            return json(DefaultResponse(201, true, '请先登录', []));
        }
        //是否运营
        $group_admin = Db::name('system_group_admin')
            ->where('admin_id',$AdminId)
            ->where('group_id',11)
            ->count();
        if ($group_admin !== 0) {
            //是运营只能看自己的业绩
            $where['admin_id'] = $AdminId;
        }else{
            if(!empty($admin_id)){
                $where['admin_id'] = $admin_id;
            }
        }
        
        if(!empty($status)){
            switch ($status) {
                case 'PersonalPart':
                    $where[] = ['admin_id','>',0];
                    $where[] = ['total_price_old','<>',0];
                    break;
                case 'CompanySection':
                    $where[] = ['admin_id','=',0];
                    break;
                default:
            }
        }else{
            $where[] = ['total_price_old','<>',0];
        }
        
        if($date){
            $where[]  = ['timedate', '>=',strtotime($date[0])];
            $where[]  = ['timedate', '<=',strtotime($date[1])];
        }
        
        $list = Db::name('report_monthly_personal')
            ->alias('a')
            ->where($where)
            ->order("date desc,commission_old desc")
            ->paginate($limit);

        $lists = $list->items();
        foreach ($lists as &$v) {
            $v['get_channel_rate'] = (float)number_format((float)$v['get_channel_rate'] * 100, 1, '.', '') . "%";
            $v['advertising_rate'] = (float)number_format((float)$v['advertising_rate'] * 100, 1, '.', '') . "%";
            //个人利润新规则
            $v['large_profit'] = (float)number_format((float)$v['total_price_handle'] - $v['freight'] - $v['material'] - $v['LogisticsMarkupFee'] - $v['advertising'] - $v['dispute'], 2, '.', '');
            
        }
                
        $data = [
            'list' => $lists,
            'total' => $list->total(),
        ];
        return json(DefaultResponse(200, true, '获取成功', $data));
    }

    /**
     * @param $params
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     * @desc 列表
     * @author zhangheng
     */
    public function exportinfo($params = [])
    {
        $admin_id = $params['admin_id'] ?? '';
        $date     = $params['date'] ?? '';
        $status     = $params['status'] ?? '';
        $where = [];

        if(!empty($admin_id)){
            $where['admin_id'] = $admin_id;
        }
        if(!empty($status)){
            switch ($status) {
                case 'PersonalPart':
                    $where[] = ['admin_id','>',0];
                    $where[] = ['total_price_old','<>',0];
                    break;
                case 'CompanySection':
                    $where[] = ['admin_id','=',0];
                    break;
                default:
            }
        }else{
            $where[] = ['total_price_old','<>',0];
        }

        if($date){
            $where[]  = ['timedate', '>=',strtotime($date[0])];
            $where[]  = ['timedate', '<=',strtotime($date[1])];
        }
        
        $list = Db::name('report_monthly_personal')
            ->alias('a')
            ->where($where)
            ->order("date desc,commission_old desc")
            ->select()->toarray();

        foreach ($list as &$v) {
            $v['get_channel_rate'] = (float)number_format((float)$v['get_channel_rate'] * 100, 1, '.', '') . "%";
            $v['advertising_rate'] = (float)number_format((float)$v['advertising_rate'] * 100, 1, '.', '') . "%";
            //个人利润新规则
            $v['large_profit'] = (float)number_format((float)$v['total_price_handle'] - $v['freight'] - $v['material'] - $v['LogisticsMarkupFee'] - $v['advertising'] - $v['dispute'], 2, '.', '');
        }

        $header[] = ['月份', 'date'];
        $header[] = ['运营', 'admin_name'];
        $header[] = ['发货单量', 'count'];
        $header[] = ['原始销售额$', 'total_price_old'];
        $header[] = ['已发货销售额$', 'total_price'];
        $header[] = ['94%销售额$', 'total_price_handle'];
        $header[] = ['账单物流费$', 'freight'];
        $header[] = ['采购成本$', 'material'];
        $header[] = ['物流加成$', 'LogisticsMarkupFee'];
        $header[] = ['广告费$', 'advertising'];
        $header[] = ['争议成本$', 'dispute'];
        // $header[] = ['小店利润$', 'small_profit'];
        $header[] = ['个人盈利$', 'large_profit'];
        // $header[] = ['渠道总利润$', 'chananel_total_shop'];
        // $header[] = ['渠道分配比例', 'advertising_rate'];
        $header[] = ['利润分配$', 'chananel_total'];
        $header[] = ['最终利润$', 'commission_old'];
        $header[] = ['提成比例', 'get_channel_rate'];
        $header[] = ['当月美金汇率', 'dollar'];
        $header[] = ['提成金额￥', 'commission'];
        
        $fileName = "业绩列表";
        
        return Excel::exportData($list, $header, $fileName, 'xlsx');

    }

    
    

    /**
     * @param $params
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     * @desc 导出历史数据
     * @desc SheCurve
     * @author zhangheng
     */
    public function exportinfoSheCurve($params = [])
    {
        $header[] = ['店铺', 'shop_name'];
        $header[] = ['日期', 'createtime'];
        $header[] = ['订单号', 'name'];
        $header[] = ['支付状态', 'financial_status'];
        $header[] = ['物流状态', 'fulfillment_status'];
        $header[] = ['原销售额$', 'old_total_price'];
        $header[] = ['退款$', 'refund_price'];
        $header[] = ['现销售额$', 'total_price'];
        $header[] = ['物流成本￥', 'freight'];
        $header[] = ['预估物流成本￥', 'estimate_freight'];
        $header[] = ['采购成本￥', 'material'];
        $header[] = ['争议成本$', 'dispute'];
        $header[] = ['币种', 'currency'];
        $header[] = ['原记录标签', 'tags'];
        $header[] = ['物流匹配状态', 'freight_status'];
        $header[] = ['采购匹配状态', 'material_status'];
        $header[] = ['争议类型', 'disputeapi_type'];
        $header[] = ['争议状态', 'disputeapi_status'];
        $header[] = ['SKU', 'sku'];
        $header[] = ['件数', 'skuquantity'];
        $header[] = ['来源', 'source'];
        $header[] = ['运营', 'username'];
        $header[] = ['状态', 'history_status'];
        $header[] = ['类型', 'history_type'];
        $header[] = ['参考月份', 'history_date'];

        $where = [];
        $where[]  = ['b.order_id', '>', 0];
        $list = Db::name('order_historical')
            ->field('
                a.shop_id,
                a.name,
                a.financial_status,
                a.fulfillment_status,
                a.createtime,
                a.freight,
                a.skuquantity,
                a.estimate_freight,
                a.material,
                a.dispute,
                a.total_price,
                a.old_total_price,
                a.refund,
                a.tags,
                a.sku,
                a.freight_status,
                a.material_status,
                a.disputeapi_type,
                a.disputeapi_status,
                a.currency,
                a.source,c.username,
                b.status as history_status,type as history_type,b.date as history_date
            ')
            ->alias('b')
            ->join('qu_order_achievement a','b.order_id = a.order_id', 'left')
            ->join('qu_system_admin c','c.id = a.admin_id', 'left')
            ->where($where)
            ->order("a.shop_id desc,a.createtime desc")
            // ->limit(10000)
            ->select()->toarray();
        foreach ($list as &$v) {
            $v['shop_name'] = "SheCurve";
            $v['createtime'] = date('Y-m-d H:i', $v['createtime']);
            if(!$v['old_total_price'] && !$v['total_price']){
                $v['refund_price']  = '0.00';
            }else{
                $v['refund_price']   =  $v['old_total_price']-$v['total_price'];
            }
            switch ($v['history_status']) {
                case '1':
                    $v['history_status'] = '满足条件';
                    break;
                case '2':
                    $v['history_status'] = '不满足业绩条件';
                    break;
                default:
                    $v['history_status'] = '未执行';
            }
            switch ($v['history_type']) {
                case '1':
                    $v['history_type'] = '之前是未发货的';
                    break;
                case '2':
                    $v['history_type'] = '之前是已发货争议中的';
                    break;
                default:
                    $v['history_type'] = '未执行';
            }
            
        }
        $fileName = "SheCurve";
        
        return Excel::exportData($list, $header, $fileName, 'xlsx');
    }

    
    /**
     * @param $params
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     * @desc 导出历史数据
     * @desc woobilly
     * @author zhangheng
     */
    public function exportinfowoobilly($params = [])
    {
        $header[] = ['店铺', 'shop_name'];
        $header[] = ['日期', 'createtime'];
        $header[] = ['订单号', 'name'];
        $header[] = ['支付状态', 'financial_status'];
        $header[] = ['物流状态', 'fulfillment_status'];
        $header[] = ['原销售额$', 'old_total_price'];
        $header[] = ['退款$', 'refund_price'];
        $header[] = ['现销售额$', 'total_price'];
        $header[] = ['物流成本￥', 'freight'];
        $header[] = ['预估物流成本￥', 'estimate_freight'];
        $header[] = ['采购成本￥', 'material'];
        $header[] = ['争议成本$', 'dispute'];
        $header[] = ['币种', 'currency'];
        $header[] = ['原记录标签', 'tags'];
        $header[] = ['物流匹配状态', 'freight_status'];
        $header[] = ['采购匹配状态', 'material_status'];
        $header[] = ['争议类型', 'disputeapi_type'];
        $header[] = ['争议状态', 'disputeapi_status'];
        $header[] = ['SKU', 'sku'];
        $header[] = ['件数', 'skuquantity'];
        $header[] = ['来源', 'source'];
        $header[] = ['运营', 'username'];
        $header[] = ['状态', 'history_status'];
        $header[] = ['类型', 'history_type'];
        $header[] = ['参考月份', 'history_date'];

        $where = [];
        $where[]  = ['b.order_id', '>', 0];
        $list = Db::name('order_historical_woob')
            ->field('
                a.shop_id,
                a.name,
                a.financial_status,
                a.fulfillment_status,
                a.createtime,
                a.freight,
                a.skuquantity,
                a.estimate_freight,
                a.material,
                a.dispute,
                a.total_price,
                a.old_total_price,
                a.refund,
                a.tags,
                a.sku,
                a.freight_status,
                a.material_status,
                a.disputeapi_type,
                a.disputeapi_status,
                a.currency,
                a.source,c.username,
                b.status as history_status,type as history_type,b.date as history_date
            ')
            ->alias('b')
            ->join('qu_order_achievement a','b.order_id = a.order_id', 'left')
            ->join('qu_system_admin c','c.id = a.admin_id', 'left')
            ->where($where)
            ->order("a.shop_id desc,a.createtime desc")
            // ->limit(10000)
            ->select()->toarray();
        foreach ($list as &$v) {
            $v['shop_name'] = "woobilly";
            $v['createtime'] = date('Y-m-d H:i', $v['createtime']);
            if(!$v['old_total_price'] && !$v['total_price']){
                $v['refund_price']  = '0.00';
            }else{
                $v['refund_price']   =  $v['old_total_price']-$v['total_price'];
            }
            switch ($v['history_status']) {
                case '1':
                    $v['history_status'] = '满足条件';
                    break;
                case '2':
                    $v['history_status'] = '不满足业绩条件';
                    break;
                default:
                    $v['history_status'] = '未执行';
            }
            switch ($v['history_type']) {
                case '1':
                    $v['history_type'] = '之前是未发货的';
                    break;
                case '2':
                    $v['history_type'] = '之前是已发货争议中的';
                    break;
                default:
                    $v['history_type'] = '未执行';
            }
            
        }
        $fileName = "woobilly";
        
        return Excel::exportData($list, $header, $fileName, 'xlsx');
    }


    /**
     * @param $params
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     * @desc 列表
     * @author zhangheng
     */
    public function PreparationWork($params = [])
    {
        $PreparationWork = (new OrderLogic())->PreparationWork();
        $TotalOrder = (new OrderLogic())->TotalOrder();
        $data = array_merge($PreparationWork, $TotalOrder);
        return json(DefaultResponse(200, true, '获取成功', $data));
    }
    /**
     * @param $params
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     * @desc 列表
     * @author zhangheng
     */
    public function LogisticsBill($params = [])
    {
        $LogisticsBill = (new OrderLogic())->LogisticsBill();
        $LogisticsCost = (new OrderLogic())->LogisticsCost();
        $data = array_merge($LogisticsBill, $LogisticsCost);
        return json(DefaultResponse(200, true, '获取成功', $data));
    }
    /**
     * @param $params
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     * @desc 列表
     * @author zhangheng
     */
    public function ProcurementBill($params = [])
    {
        $ProcurementBill = (new OrderLogic())->ProcurementBill();
        $ProcurementCost = (new OrderLogic())->ProcurementCost();
        $data = array_merge($ProcurementBill, $ProcurementCost);
        return json(DefaultResponse(200, true, '获取成功', $data));
    }
    /**
     * @param $params
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     * @desc 列表
     * @author zhangheng
     */
    public function DisputeCost($params = [])
    {
        $DisputeCost = (new OrderLogic())->DisputeCost();
        $Adv_inspect = (new OrderLogic())->Adv_inspect();
        $shop_admin_inspect = (new OrderLogic())->shop_admin_inspect();
        $data = array_merge($DisputeCost, $Adv_inspect, $shop_admin_inspect);
        return json(DefaultResponse(200, true, '获取成功', $data));
    }
    /**
     * @param $params
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     * @desc 列表
     * @author zhangheng
     */
    public function OrderTagMatching($params = [])
    {
        $data = (new OrderLogic())->OrderTagMatching();
        return json(DefaultResponse(200, true, '获取成功', $data));
    }

    /**
     * @param $params
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     * @desc 导出
     * @author zhangheng
     */
    public function export123($params = [])
    {
        $header = [];

        $header[] = ['订单名称', 'name'];
        $header[] = ['产品', 'product'];
        // $header[] = ['订单ID', 'order_id'];
        $header[] = ['订单购买数量', 'quantity'];
        $header[] = ['SPU', 'spu'];
        $header[] = ['SPU采购单价￥', 'material'];
        // $header[] = ['SKU', 'sku'];
        $header[] = ['SKU件数', 'count'];
        $header[] = ['总采购价￥', 'material_total'];
        $header[] = ['总件数', 'count_total'];

        // $date = date('Y-m', time()); 
        // $timedate = strtotime($date);
        // $firstday = date("Y-m-d", $timedate);
        // $end_time = strtotime(date("Y-m-d", strtotime("$firstday +1 month")));

        // $timedate = "1725120000";
        // $end_time = "1725206399";

        $timedate = "1725638400";
        $end_time = "1725724800";

        $where[]  = ['b.createtime', '>=', $timedate];
        $where[]  = ['b.createtime', '<=', $end_time];
        $where[]  = ['b.shop_id', '=', 17];
        $where[]  = ['b.financial_status', 'in', ["partially_paid", "paid", "partially_refunded", "refunded"]];
        
        $order_info = Db::name('order_info')
            ->field('
                b.name as name,
                a.spu as spu,
                a.name as product,
                SUM(a.quantity) as quantity,
                SUM(a.count) as count,
                SUM(a.material) as material,
                SUM(a.count_total) as count_total,
                SUM(a.material_total) as material_total
            ')
            ->alias('a')
            ->join('order_achievement b','b.order_id = a.order_id', 'left')
            ->where($where)
            ->group('a.spu')
            ->select()
            ->toarray();

        $fileName = "业绩";
        return Excel::exportData($order_info, $header, $fileName, 'xlsx');

        halt(1);
    }

    /**
     * @param $params
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     * @desc 导出
     * @author zhangheng
     */
    public function export1234($params = [])
    {
        $header = [];

        $header[] = ['订单名称', 'name'];
        $header[] = ['产品', 'product'];
        // $header[] = ['订单ID', 'order_id'];
        $header[] = ['订单购买数量', 'quantity'];
        $header[] = ['SPU', 'spu'];
        $header[] = ['SPU采购单价￥', 'material'];
        $header[] = ['SKU', 'sku'];
        $header[] = ['SKU件数', 'count'];
        $header[] = ['总采购价￥', 'material_total'];
        $header[] = ['总件数', 'count_total'];

        // $date = date('Y-m', time()); 
        // $timedate = strtotime($date);
        // $firstday = date("Y-m-d", $timedate);
        // $end_time = strtotime(date("Y-m-d", strtotime("$firstday +1 month")));

        // $timedate = "1725120000";
        // $end_time = "1725206399";

        $timedate = "1725638400";
        $end_time = "1725724800";

        $where[]  = ['b.createtime', '>=', $timedate];
        $where[]  = ['b.createtime', '<=', $end_time];
        $where[]  = ['b.shop_id', '=', 17];
        $where[]  = ['b.financial_status', 'in', ["partially_paid", "paid", "partially_refunded", "refunded"]];
        
        $order_info = Db::name('order_info')
            ->field('
                b.name,
                a.order_id,
                a.sku,
                a.spu,
                a.name as product,
                a.quantity,
                a.count,
                a.material,
                a.count_total,
                a.material_total
            ')
            ->alias('a')
            ->join('order_achievement b','b.order_id = a.order_id', 'left')
            ->where($where)
            ->select()
            ->toarray();

        $fileName = "业绩";
        return Excel::exportData($order_info, $header, $fileName, 'xlsx');

        halt(1);
    }

    /**
     * @param $params
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     * @desc 导出
     * @author zhangheng
     */
    public function export($params = [])
    {
        $status = $params['status'] ?? "";

        $header = [];
        if($status == 'SmallShop'){
            $header[] = ['店铺', 'shop_name'];
        }
        if($status == ''){
            $header[] = ['店铺', 'shop_name'];
        }
        $header[] = ['日期', 'createtime'];
        $header[] = ['订单号', 'name'];
        $header[] = ['支付状态', 'financial_status'];
        $header[] = ['物流状态', 'fulfillment_status'];
        $header[] = ['原销售额$', 'old_total_price'];
        $header[] = ['退款$', 'refund_price'];
        $header[] = ['现销售额$', 'total_price'];
        $header[] = ['物流成本￥', 'freight'];
        $header[] = ['预估物流成本￥', 'estimate_freight'];
        $header[] = ['采购成本￥', 'material'];
        $header[] = ['争议成本$', 'dispute'];
        // $header[] = ['美金汇率', 'dollar'];
        $header[] = ['币种', 'currency'];
        $header[] = ['原记录标签', 'tags'];
        $header[] = ['物流匹配状态', 'freight_status'];
        $header[] = ['采购匹配状态', 'material_status'];
        $header[] = ['争议类型', 'disputeapi_type'];
        $header[] = ['争议状态', 'disputeapi_status'];
        $header[] = ['SKU', 'sku'];
        $header[] = ['件数', 'skuquantity'];
        $header[] = ['来源', 'source'];

        //id参数
        $id = $params['id'];
        $report_monthly_personal = Db::name('report_monthly_personal')->where('id',$id)->find();
        if(empty($report_monthly_personal)){
            return json(DefaultResponse(200, true, '暂无数据'));
        }
        $date = $report_monthly_personal['date'];
        $source = $report_monthly_personal['source'];
        
        $admin_id = $report_monthly_personal['admin_id'];

        $start_time = strtotime($date);
        $end_time = strtotime("+1 month", strtotime($date . "-01"));  
        $where[]  = ['createtime', '>=', $start_time];
        $where[]  = ['createtime', '<=', $end_time];
        $where[]  = ['financial_status', 'in', ["partially_paid", "paid", "partially_refunded", "refunded"]];
        if($admin_id !== 85){
            $where[]  = ['fulfillment_status', 'in', ["fulfilled", "restocked","partial"]];
        }

        $status = $params['status'] ?? "";
        if(!empty($status)){
            switch ($status) {
                case 'fb':
                    $where[]  = ['source', 'in', ["fb", "tt"]];
                    $where[]  = ['admin_id', '=', $admin_id];
                    break;
                case 'email':
                    $where[]  = ['source', 'in', ["email", "ggad", "impact"]];
                    $where[]  = ['admin_id', '=', $admin_id];
                    break;
                case 'WithinTheChannel':
                    $where[]  = ['source', '=', $source];
                    $where[]  = ['admin_id', '<=', 0];
                    $where[]  = ['shop_id', 'in', [17, 5]];
                    break;
                case 'DirectCurrent':
                    $where[]  = ['source', 'in', ["other", "直接访问"]];
                    $where[]  = ['shop_id', 'in', [17, 5]];
                    break;
                case 'SheCurve':
                    $where[]  = ['admin_id', '=', $admin_id];
                    $where[]  = ['shop_id', '=', 17];
                    break;
                case 'SmallShop':
                    $where[]  = ['admin_id', '=', $admin_id];
                    $where[]  = ['shop_id', 'not in', [17, 5]];//大店
                    //TODO 特殊规则 7月业绩不算WomenForSure ,LilyLove用大店模式显示
                    if($date == '2024-07'){
                        $where[]  = ['shop_id', 'not in', [17, 5,10,18]];
                    }
                    break;
                default:
            }
        }else{
            $where[]  = ['admin_id', '=', $admin_id];
        }

        $list = Db::name('order_achievement')
            ->field('
                shop_id,
                name,
                financial_status,
                fulfillment_status,
                createtime,
                freight,
                skuquantity,
                estimate_freight,
                material,
                dispute,
                total_price,
                old_total_price,
                refund,
                tags,
                sku,
                freight_status,
                material_status,
                disputeapi_type,
                disputeapi_status,
                currency,
                source
            ')
            ->where($where)
            ->order("shop_id desc,createtime desc")
            // ->limit(10000)
            ->select()->toarray();

        
        //汇率
        // $order_exchange = Db::name('order_exchange')
        //     ->where(['date' => $date])
        //     ->find();

        // $source = "";
        // if($status == 'SmallShop'){
        //     $shops = Db::name('shops')
        //         ->field("id,name")
        //         ->column('name', 'id');
        //     foreach ($list as &$v) {
        //         $v['createtime'] = date('Y-m-d H', $v['createtime']);
        //         $v['shop_name'] = $shops[$v['shop_id']];
        //     }
        // }
        $shops = Db::name('shops')
            ->field("id,name")
            ->column('name', 'id');
        foreach ($list as &$v) {
            $v['shop_name'] = $shops[$v['shop_id']];
            $v['createtime'] = date('Y-m-d H:i', $v['createtime']);
            if(!$v['old_total_price'] && !$v['total_price']){
                $v['refund_price']  = '0.00';
            }else{
                $v['refund_price']   =  $v['old_total_price']-$v['total_price'];
            }
            // 判断金额
            // $MonthlyDistributionLogic = new MonthlyDistributionLogic();
            // $v = $MonthlyDistributionLogic->handling_performance($v,$order_exchange);
            // 计算利润
            // if(empty($source) && !empty($v['source'])){
            //     $source = $v['source'];
            // }
        }
        // halt($list);

        $fileName = $report_monthly_personal['date']."".$report_monthly_personal['admin_name']."业绩";
        
        return Excel::exportData($list, $header, $fileName, 'xlsx');
    }

    
    /**
    * @desc    单人店铺业绩
    * @date    2024/8/10
    * @author  zhangheng
    */
    public function SinglePersonStorePerformance($shops_admin)
    {
        $where[]  = ['shop_id', '=', $shops_admin['shop_id']];
        $where[]  = ['createtime', '>=', $shops_admin['createtime']];
        $where[]  = ['createtime', '<=', $shops_admin['updatetime']];
        $where[]  = ['financial_status', 'in', ["partially_paid", "paid", "partially_refunded", "refunded"]];

        $lists = Db::name('order_achievement')
            ->field('
                name,
                createtime,
                financial_status,
                fulfillment_status,
                createtime,
                freight,
                skuquantity,
                estimate_freight,
                material,
                dispute,
                total_price,
                refund,
                tags,
                sku,
                freight_status,
                material_status,
                disputeapi_type,
                disputeapi_status,
                currency
            ')
            ->where($where)
            ->order('createtime asc')
            ->select()->toarray();
        return $lists;
    }

    /**
    * @desc    多人店铺业绩
    * @date    2024/8/10
    * @author  zhangheng
    */
    public function MultiPersonStorePerformance($shops_admin)
    {
        $where[]  = ['shop_id', '=', $shops_admin['shop_id']];
        $where[]  = ['createtime', '>=', $shops_admin['createtime']];
        $where[]  = ['createtime', '<=', $shops_admin['updatetime']];
        $where[]  = ['financial_status', 'in', ["partially_paid", "paid", "partially_refunded", "refunded"]];
        if(!empty($shops_admin['label'])){
            $where[] = array('tags', 'LIKE', '%' . trim($shops_admin['label']) . '%');
            $lists = Db::name('order_achievement')
                ->field('
                    name,
                    createtime,
                    financial_status,
                    fulfillment_status,
                    createtime,
                    freight,
                    skuquantity,
                    estimate_freight,
                    material,
                    dispute,
                    total_price,
                    refund,
                    tags,
                    sku,
                    freight_status,
                    material_status,
                    disputeapi_type,
                    disputeapi_status,
                    currency
                ')
                ->where($where)
                ->order('createtime asc')
                ->select()->toarray();
        }else{
            $shops_admin_other = Db::name('shops_admin')
                ->field('label')
                ->where('shop_id',$shops_admin['shop_id'])
                ->where('admin_id',"<>",$shops_admin['admin_id'])
                ->select()->toarray();
            foreach ($shops_admin_other as $label) {  
                $where[] = ['tags', 'NOT LIKE', '%' . $label['label'] . '%'];  
            }
            $lists = Db::name('order_achievement')
                ->field('
                    name,
                    createtime,
                    financial_status,
                    fulfillment_status,
                    createtime,
                    freight,
                    skuquantity,
                    estimate_freight,
                    material,
                    dispute,
                    total_price,
                    refund,
                    tags,
                    sku,
                    freight_status,
                    material_status,
                    disputeapi_type,
                    disputeapi_status,
                    currency
                ')
                ->where($where)
                ->order('createtime asc')
                ->select()->toarray();
        }
        return $lists;
    }
}
